<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <script>
        var arr = [1, 24, 1, 5, 12, 1, 1, 1, 1, 1, 2, 3];
        //冒泡
        function rank(arr, how) {
            var newArr = arr.concat(),
                flag = true;
            for (var i = 0; i < newArr.length - 1; i++, flag = true) {
                for (var j = 0; j < newArr.length - i - 1; j++) {
                    if (newArr[j] > newArr[j + 1]) {
                        var temp = newArr[j];
                        newArr[j] = newArr[j + 1];
                        newArr[j + 1] = temp;
                        flag = false;
                    }
                }
                if (flag) break;
            }
            return newArr;
        }
        //快速排序
        function fast(arr) {
            if (arr.length < 2) return arr;
            var newArr = arr.concat(),
                low = [],
                big = [];
            for (var i = 1; i < newArr.length; i++) {
                newArr[0] > newArr[i] ? low.push(newArr[i]) : big.push(newArr[i]);
            }
            return fast(low).concat(newArr[0], fast(big));
        }
    </script>
</body>

</html>